﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Loki.Utils;
using NUnit.Framework;

namespace Loki.Core.Test
{
	[TestFixture]
	public class HashTest : AssertionHelper
	{

		string password = "myP@5sw0rd";  // original password
		string wrongPassword = "password";    // wrong password

		[Test]
		public void TestMD5True()
		{
			string passwordHashMD5 = HashHelper.ComputeHash(password, HashAlgorithmType.MD5);
			Expect(
				HashHelper.VerifyHash(password, HashAlgorithmType.MD5, passwordHashMD5),
				Is.True);
		}

		[Test]
		public void TestMD5False()
		{
			string passwordHashMD5 = HashHelper.ComputeHash(password, HashAlgorithmType.MD5);
			Expect(
				HashHelper.VerifyHash(wrongPassword, HashAlgorithmType.MD5, passwordHashMD5),
				Is.False);
		}

		[Test]
		public void TestSHA1True()
		{
			string passwordHashSha1 = HashHelper.ComputeHash(password, HashAlgorithmType.SHA1);
			Expect(
				HashHelper.VerifyHash(password, HashAlgorithmType.SHA1, passwordHashSha1),
				Is.True);
		}

		[Test]
		public void TestSHA1False()
		{
			string passwordHashSha1 = HashHelper.ComputeHash(password, HashAlgorithmType.SHA1);
			Expect(
				HashHelper.VerifyHash(wrongPassword, HashAlgorithmType.SHA1, passwordHashSha1),
				Is.False);
		}

		[Test]
		public void TestSHA256True()
		{
			string passwordHashSHA256 = HashHelper.ComputeHash(password, HashAlgorithmType.SHA256);
			Expect(
				HashHelper.VerifyHash(password, HashAlgorithmType.SHA256, passwordHashSHA256),
				Is.True);
		}

		[Test]
		public void TestSHA256False()
		{
			string passwordHashSHA256 = HashHelper.ComputeHash(password, HashAlgorithmType.SHA256);
			Expect(
				HashHelper.VerifyHash(wrongPassword, HashAlgorithmType.SHA256, passwordHashSHA256),
				Is.False);
		}

		[Test]
		public void TestSHA384True()
		{
			string passwordHashSHA384 = HashHelper.ComputeHash(password, HashAlgorithmType.SHA384);
			Expect(
				HashHelper.VerifyHash(password, HashAlgorithmType.SHA384, passwordHashSHA384),
				Is.True);
		}

		[Test]
		public void TestSHA384False()
		{
			string passwordHashSHA384 = HashHelper.ComputeHash(password, HashAlgorithmType.SHA384);
			Expect(
				HashHelper.VerifyHash(wrongPassword, HashAlgorithmType.SHA384, passwordHashSHA384),
				Is.False);
		}

		[Test]
		public void TestSHA512True()
		{
			string passwordHashSHA512 = HashHelper.ComputeHash(password, HashAlgorithmType.SHA512);
			Expect(
				HashHelper.VerifyHash(password, HashAlgorithmType.SHA512, passwordHashSHA512),
				Is.True);
		}

		[Test]
		public void TestSHA512False()
		{
			string passwordHashSHA512 = HashHelper.ComputeHash(password, HashAlgorithmType.SHA512);
			Expect(
				HashHelper.VerifyHash(wrongPassword, HashAlgorithmType.SHA512, passwordHashSHA512),
				Is.False);
		}
	}
}
